<?php

/* Template name: Portfolio Page */

?>

<?php

	$back_to_the_portfolio_link = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
	update_option( "back_to_the_portfolio_link", $back_to_the_portfolio_link );
	
	$page_all = get_page( get_the_ID() );
	$page_slug = $page_all->post_name;
	// update_option( "portfolio_slug_name_for_url", $page_slug );
	
?>

<?php

	get_header();
	
?>
     
        <!-- MIDDLE -->
        <section class="middle row">
		
            <!-- PORTFOLIO WRAP -->
            <div class="portfolio-wrap span12">

                <!-- PAGE HEADER -->
                <div class="page-header">
				
					<h1 style="float: left; min-width: 50%;">
					
						<b><?php single_post_title(); ?></b>
						
						<small><?php echo stripcslashes( get_option( get_the_ID() . 'page_subtitle' ) ); ?></small>
						
					</h1>
					
					<?php
					
						if ( ! get_option( 'disable_portfolio_search' ) )
						{
							?>
								<form style="float: right; margin-bottom: 0px; padding-top: 4px;" method="get" action="<?php echo home_url( '/' ); ?>">
								
									<div class="input-append" style="margin-bottom: 0px;">
									
										<input type="text" id="appendedPrependedInput" name="s" size="16" class="span3" style="padding: 6px !important; margin-bottom: 0px; max-width: 220px;" placeholder="<?php echo __( 'Enter keyword...', 'responsy' ); ?>" value="<?php the_search_query(); ?>">
										
										<input type="submit" id="searchsubmit" class="send" style="display: none;" value="Go">
										
									  </div>
									  
								</form>
							<?php
						}
					
					?>
					
					<div style="clear: both;"></div>
					
				</div>
                <!-- end PAGE HEADER -->
               
                <!--FILTERS-->
				<?php
				
					$pf_terms = get_categories( 'type=portfolio&taxonomy=department' );
					
				?>
				
                <ul id="filters">
				
					<?php
					
						if ( count( $pf_terms ) >= 1 )
						{
							?>
							
								<li class="current">
								
									<a href="#" data-filter="*"><?php echo __( 'all', 'responsy' ); ?></a>
									
								</li>
								
							<?php
						}
					
					?>
					
					<?php
					
						foreach ( $pf_terms as $pf_term ) :
						
							?>
							
								<li>
								
									<a href="#" data-filter=".<?php echo $pf_term->slug; ?>"><?php echo $pf_term->name; ?></a>
									
								</li>
								
							<?php
					
						endforeach;
						
					?>
					
                </ul>
                <!-- end FILTERS -->

                <!-- PORTFOLIO -->
                <div id="portfolio" class="portfolio-items">
				
					<?php
					
						$args_portfolio = array( 'post_type' => 'portfolio', 'posts_per_page' => -1 );
						$loop_portfolio = new WP_Query( $args_portfolio );
						
						if ( $loop_portfolio->have_posts() ) :
						
							while ( $loop_portfolio->have_posts() ) : $loop_portfolio->the_post();
								
								$terms = get_the_terms( $post->ID, 'department' );
								$on_draught = '';
								
								if ( $terms && ! is_wp_error( $terms ) ) :
									
									$draught_links = array();

									foreach ( $terms as $term )
									{
										$draught_links[] = $term->slug;
									}
							
									$on_draught = join( " ", $draught_links );
									
								endif;
							
							?>
							
							<div class="item <?php echo $on_draught; ?>">
							
								<div class="media-box">
								
									<?php
									
										if ( has_post_thumbnail() )
										{
											if ( get_option( 'no_crop_portfolio_page' ) )
											{
												the_post_thumbnail( 'full', array( 'alt' => get_the_title(), 'title' => "" ) );
											}
											else
											{
												the_post_thumbnail( 'portfolio_page_img', array( 'alt' => get_the_title(), 'title'	=> "" ) );
											}
										}
										else
										{
											?>
												<img src="<?php echo get_template_directory_uri(); ?>/img/blog/blog-placeholder.png" alt="<?php echo get_the_title(); ?>">
											<?php
										}
									?>
									
									<div class="mask">
									
										<h3 class="title"><?php if ( get_option( 'see_project_details_text' ) != "" ) { echo stripcslashes( get_option( 'see_project_details_text' ) ); } else { echo "SEE PROJECT DETAILS"; } ?></h3>
										
										<?php
											
											$enable_pretty_photo = '';
											$pretty_photo_title = '';
											
											if ( get_post_meta( $post->ID, 'project_url_new_window', true ) )
											{
												$direct_url_new_tab = 'target="_blank"';
											}
											else
											{
												$direct_url_new_tab = '';
											}
										
											if ( get_option( $post->ID . 'open_portfolio_item_in_lightbox' ) )
											{
												if ( has_post_thumbnail() )
												{
													$portfolio_item = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
													
													$portfolio_item_url = $portfolio_item[0];
												}
												else
												{
													$portfolio_item_url = get_template_directory_uri() . '/img/blog/blog-placeholder.png';
												}
												
												$enable_pretty_photo = 'rel="prettyPhoto[portfolio]"';
												$pretty_photo_title = 'title="' . get_the_title() . '"';
											}
											elseif ( get_option( $post->ID . 'project_direct_url' ) )
											{
												$portfolio_item_url = get_post_meta( $post->ID, 'launch_project_url', true );
											}
											else
											{
												$portfolio_item_url = get_permalink();
											}
											
										?>
										
										<a class="ico full" <?php echo $direct_url_new_tab; ?> href="<?php echo $portfolio_item_url; ?>" <?php echo $enable_pretty_photo . ' ' . $pretty_photo_title; ?>></a>
										
									</div>
									
								</div>
								
								<h3 class="project-title"><?php the_title(); ?></h3>
								
								<p class="category"><?php echo get_post_meta( $post->ID, 'short_description', true ); ?></p>
								
							</div>
							
							<?php
							
							endwhile;
							
						endif;
						
						wp_reset_query();
					
					?>
				
                </div>
                <!-- end PORTFOLIO -->
				
            </div>
            <!-- end PORTFOLIO WRAP -->
			
			<div class="span12">
			
				<?php
				
					if ( have_posts() ) :

						while ( have_posts() ) : the_post();
					
							the_content();
						
							echo '<div class="row"><div class="span8">';
						
							comments_template( '', true );
						
							echo '</div></div>';
						
						endwhile;
					
					endif;
				
				?>
			
			</div>
			<!-- end content and comments -->
		
        </section>
        <!-- end MIDDLE -->
	
    </div>
    <!-- end CONTAINER -->
   
<?php

	get_footer();
	
?>